import { getImToken, disconnectIm } from "@/utils/rongIMLib/user.js";

const state = {
    token: '',
    imUserInfo: {}, // 我的 IM 用户信息，包括token
    conversationList: [], // IM 会话列表
    clickImUser: {}, // 点击会话的好友信息，用于与会话详情的信息对比，用户信息是否有更新
    receiverUser: {}, // 当前会话的好友信息
    msgList: [], // 当前会话的消息列表
    unreadcount: 0, // 用户IM消息为读数
    userInfo: {},
    mapData: {}, // 选着地址信息
    draftRecordData: {}, //  用户右滑存的草稿和草稿箱的区分
    userVideoFlowList: [], // 个人主页视频流
    posterSharingData: {}, // 海报分享
    editAddressMsgData: {}, // 编辑地址信息
    choiceAddressData: {}, //选择的收货地址
    myReleaseVideoList: [], // 我的页面视频流列表
    myReleaseVideoParams: {}, // 我的页面视频流数据参数
    othersInfoData: '', // 主页信息
    followTypeObj: null, // 个人主页关注后的状态
    draftsCount: 0, // 草稿箱数量
    shareVideoFlowList: [], // 分享视频
    myPageInfo: {},
    pageSharingData: {}, // 页面分享参数数据
    loginShareIdCode: "", // 分享者的IDCODE 用于登录时传入绑定关系
}

const mutations = {
    TOKEN(state, token) {
        state.token = token
        if (token) {
            getImToken() // 用户token变化时，重新获取用户IM的token
        } else {
            disconnectIm() // 断开IM链接
        }
        uni.setStorageSync('token', token)
    },
    SET_IM_USERINFO(state, data) {
      state.imUserInfo = data
    },
    SET_CONVERSATIONLIST(state, data){
        state.conversationList = data
    },
    SET_CLICKUSER(state, data){
        state.clickImUser = data
    },
    SET_RECEIVERUSER(state, data){
        state.receiverUser = data
    },
    SET_MESSAGE_LIST(state, data){
        state.msgList = data
    },
    SET_IM_UNREADCOUNT(state, data){
        state.unreadcount = data
    },
    USERINFO (state, userInfo) {
        state.userInfo = userInfo
        uni.setStorageSync('userInfo',userInfo)
    },
    MAP_DATA (state, mapData) {
        state.mapData = mapData
    },
    DRAFT_RECORD_DATA (state, draftRecordData) {
        state.draftRecordData = draftRecordData
    },
    USER_VIDEO_FLOW_LIST (state, userVideoFlowList) {
        state.userVideoFlowList = userVideoFlowList
    },
    POSTER_SHARING_DATA (state, posterSharingData) {
        state.posterSharingData = posterSharingData
    },
    EDIT_ADDRESS_MSG_DATA (state, editAddressMsgData) {
        state.editAddressMsgData = editAddressMsgData
    },
    CHOICE_ADDRESS_DATA (state, choiceAddressData) {
        state.choiceAddressData = choiceAddressData
    },
    MY_RELEASE_VIDEO_LIST (state, myReleaseVideoList) {
        state.myReleaseVideoList = myReleaseVideoList
    },
    MY_RELEASE_VIDEO_PARAMS (state, myReleaseVideoParams) {
        state.myReleaseVideoParams = myReleaseVideoParams
    },
    OTHERS_INFO_DATA (state, othersInfoData) {
        state.othersInfoData = othersInfoData
    },
    FOLLOW_TYPE (state, followTypeObj) {
        state.followTypeObj = followTypeObj
    },
    DRAFTS_COUNT (state, draftsCount) {
        state.draftsCount = draftsCount
    },
    SHARE_VIDEO_FLOW_LIST (state, shareVideoFlowList) {
        state.shareVideoFlowList = shareVideoFlowList
    },
    SET_MY_PAGEINFO(state, data){
        state.myPageInfo = data
    },
    PAGE_SHARING_DATA (state, pageSharingData) {
        state.pageSharingData = pageSharingData
    },
    LOGIN_SHARE_IDCODE (state, loginShareIdCode) {
        state.loginShareIdCode = loginShareIdCode
    }
}

// const getters = {
//     token: (state) => state.token || '',
//     imUserInfo: (state) => state.imUserInfo || {}
// }

export default {
    state,
    mutations
}